package frobagroup.controller.backstage;

import frobagroup.pagination.Pagination;
import frobagroup.services.backstage.UserService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Tinsley on 2018/5/22.
 */
@RequestMapping("/webAPI/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/findUserList", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findUserList(@RequestBody Pagination pagination, HttpServletRequest request) throws ServletException {
        return ResponseModel.success(userService.findUserList((String)request.getAttribute("id"),pagination), Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/findUserDetail/{uId}", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findUserDetail(@PathVariable String uId, HttpServletRequest request) throws ServletException {
        return ResponseModel.success(userService.findUserDetail(uId), Constants.RESPONSE_STATUS_SUCESS);
    }

}
